package net.cz.wc.data;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionManager {
	
	private static final String CONNECTION_STRING = "jdbc:postgresql://localhost:5432/wc";
	private static final String user = "postgres";
	private static final String password = "Asdf1234$";
	
	/**
	 * returns a new connection to the default database
	 * @return new java.sql.Connection
	 */
	public static Connection getConnection() {
		Connection conn = null;
		try {
			Class.forName("org.postgresql.Driver");
			conn = DriverManager.getConnection(CONNECTION_STRING, user, password);
		} catch (Exception ee) {
			ee.printStackTrace();
		}
		
		return conn;
	}
	
	public static void closeConnection(Connection conn) {
		try {
			if (conn != null && !conn.isClosed()) {
				conn.close();
			}
		} catch (SQLException ssEE) {
			//nothing to do here but to shape sonar complaints
		}
	}
}
